/*
 LoadingViewController.m
 
 The view controller that handles the window that appears when loading an image
 onto the canvas.
 
 Created by David Kikuta.
 */

#import "LoadingViewController.h"

@implementation LoadingViewController

@synthesize delegate, imagePickerController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
    {
        self.imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
        self.imagePickerController.delegate = self;
    }
    return self;
}

// called when the parent application receives a memory warning
- (void)didReceiveMemoryWarning {
    // we have been warned that memory is getting low, stop all timers
    [super didReceiveMemoryWarning];
}

// update the UI after an image has been chosen or picture taken
- (void)finishAndUpdate {
    [self.delegate finishedPicking];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    
    // give the taken picture to our delegate
    if (self.delegate) {
        [self.delegate didTakePicture:image];
	}
    
	[self finishAndUpdate];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self.delegate finishedPicking];    // tell our delegate we are finished with the picker
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

- (void)dealloc {	
    [imagePickerController release];
    [super dealloc];
}

@end
